package com.yyplatform.admin.platform.schedule.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.yyplatform.admin.platform.schedule.model.entity.JobEntity;

/**
 * Created on 2024-09-14
 */
public interface JobRepository extends JpaRepository<JobEntity, Long>,
        JpaSpecificationExecutor<JobEntity> {


    @Query(
            value =
                    "SELECT * FROM sys_schedule_job WHERE 1=1 "
                            + " AND if(:beanName != '' , `bean_name` LIKE concat('%', :beanName, '%'), 1=1 )  "
                            + " AND if(:status != null , `status` = :status, 1=1 ) ",
            countQuery =
                    "SELECT count(id) FROM sys_schedule_job WHERE 1=1 "
                            + " AND if(:beanName != '' , `bean_name` LIKE concat('%', :beanName, '%'), 1=1 )  "
                            + " AND if(:status != null , `status` = :status, 1=1 ) ",
            nativeQuery = true)
    Page<JobEntity> find(
            @Param("beanName") String beanName,
            @Param("status") Integer status,
            @Param("pageRequest") PageRequest pageRequest);

}
